-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple script vm #407
Simple script vm #407
Conversation
* - undefined if no tokens are approved | ||
* - 'unknown' if the tokens cannot be determined | ||
* - an array of tokens if the tokens are known | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have better types for this?
break | ||
} | ||
default: | ||
unimplemented(instr.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instructions that are not used much in TxScript are not implemented for now.
break | ||
case 'Dup': | ||
const val = operandStack.pop() | ||
operandStack.push(val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to push the val
twice for the Dup
instr.
type SimulatorVar<K extends string, V> = { kind: K; value: V } | { kind: `Symbol-${K}`; value: undefined } | ||
|
||
function unaryOp<K extends string, V>(x: SimulatorVar<K, V>, op: (x: V) => V): SimulatorVar<K, V> { | ||
if (x.kind.startsWith('symbol')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to use Symbol
instead of symbol
in these *Op
functions? It seems that 'Symbol-Bool'.startsWith('symbol')
returns false.
test/transact.test.ts
Outdated
expect(getCalls1[0].approvedTokens).toBe(undefined) | ||
}) | ||
|
||
it.only('should use transact methods for token', async function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to remove the only
here?
test/transact.test.ts
Outdated
expect(deployCalls2.length).toBe(0) | ||
}) | ||
|
||
it.only('should test multicall', async function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
if (spender.kind.startsWith('Symbol')) { | ||
approved.setUnknown() // The spender might be the caller | ||
} else if (spender === callerAddress) { | ||
approved.addApprovedAttoAlph(amount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we set the approved to unknown
as well if callerAddress
isn't spender?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only show the approvals for call address in the return, so we don't need to care about other addresses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking about perhaps this would underestimate the total amount of approvals in corner cases, since we could have something like
foo.call{callerAddress!() -> 1 alph, alice -> 2 alph)(...)
where alice is actually the same as callerAddress!(). Could this happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If alice's address is unknown, then branch spender.kind.startsWith('Symbol')
will be executed, the approved assets would be set to unknown.
If alice's address is known, then we will compare if the address is equal to caller address.
A symbolic execution vm for tx scripts. Most of the TxScript instructions are implemented, we could add more based on feedback.
Not many unit tests for now as I don't have much time. We could add them in the future.